home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr47 / 80x0393.zip / CRC16.ASM < prev    next >
Assembly Source File  |  1993-06-20  |  1KB  |  45 lines

  1. ; Written by Chris Barrett (3:690/660.25)                        
  2. ; The following non table-based routine produces the same CRC16's
  3. ; as required by the EMSI standard so I assume it's correct.     
  4. ; Released into the Public Domain                                
  5.  
  6. ; Pass    - DS:SI = pointer to the buffer
  7. ;         - CX    = length of the buffer 
  8. ; Returns - DX    = CRC16 of the buffer  
  9.  
  10. CRC16    PROC NEAR
  11.  
  12.          PUSH AX
  13.          PUSH BX
  14.          PUSHF
  15.          CLD                      ; Move forward through the buffer
  16.  
  17.          SUB  DX,DX               ; CRC := 0000h
  18.  
  19. C1:      LODSB                    ; AL := byte at DS:SI
  20.          SUB  AH,AH
  21.  
  22.          XCHG AH,AL               ; AX := 256 * AL
  23.          XOR  DX,AX               ; CRC := CRC xor AX
  24.  
  25.          PUSH CX
  26.          MOV  CX,8
  27.  
  28. C2:      MOV  BX,DX
  29.          SHL  DX,1
  30.  
  31.          AND  BX,8000h
  32.          JZ   C3
  33.  
  34.          XOR  DX,1021h
  35. C3:      LOOP C2
  36.          POP  CX
  37.  
  38.          LOOP C1
  39.  
  40.          POPF
  41.          POP  BX
  42.          POP  AX
  43.          RET
  44. CRC16    ENDP
  45.